package tk.pptiger.controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// 不方便的地方在于：通常情况下，一个文件只能定义一个 servlet

// loadOnStartup(大于0,默认是 -1) 指定是不是在容器初始化的时候就加载这个 servlet
// 而且值越小的 servlet 类需要先初始化
// web.xml 中的设置优先级要高于标注中的设置
@WebServlet(name="BaseServlet", urlPatterns={"/hello"}, loadOnStartup=1)
public class BaseServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Hello Servlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1> Hello! World ?!</h1>");
        out.println("</body>");
        out.println("</html>");
        out.close();
    }
}
